<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js"> <!--<![endif]-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title><?php echo CHtml::encode($this->pageTitle); ?></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0">

    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,400italic,700,700italic">
    <?php
    $template = $this->templateConfigs();
    $bodyClasses = '';

    if ($template['header'] == 'fixed-top')
        $bodyClasses = 'header-fixed-top';
    else if ($template['header'] == 'fixed-bottom')
        $bodyClasses = 'header-fixed-bottom';

    if ($template['side_content'])
        $bodyClasses .= ' ' . $template['side_content'];

    Yii::app()->clientScript->registerCssFile(Yii::app()->BaseUrl . '/css/back/bootstrap.css');
    Yii::app()->clientScript->registerCssFile(Yii::app()->BaseUrl . '/css/back/plugins.css');
    Yii::app()->clientScript->registerCssFile(Yii::app()->BaseUrl . '/css/back/main.css');
    Yii::app()->clientScript->registerCssFile(Yii::app()->BaseUrl . '/css/jquery-ui.css');
    Yii::app()->clientScript->registerCssFile(Yii::app()->BaseUrl . '/css/fancybox/jquery.fancybox.css');
    ?>

    <?php if ($template['theme']): ?>
        <link id="theme-link" rel="stylesheet" href="css/back/themes/<?php echo $template['theme']; ?>.css">
    <?php endif; ?>

    <?php
    Yii::app()->clientScript->registerCoreScript('jquery');
    Yii::app()->clientScript->registerScriptFile(Yii::app()->BaseUrl . '/js/jquery-ui-1.10.4.custom.js');
    Yii::app()->clientScript->registerScriptFile(Yii::app()->BaseUrl . '/js/tretoday.core.js');
    Yii::app()->clientScript->registerScriptFile(Yii::app()->BaseUrl . '/kindeditor-4.1.4/kindeditor.js');
    Yii::app()->clientScript->registerScriptFile(Yii::app()->BaseUrl . '/js/jquery.fancybox.js');
    ?>
</head>

<body<?php if ($bodyClasses)
    echo ' class="' . $bodyClasses . '"'; ?>>
<!-- Page Container -->
<div id="page-container"<?php if ($template['page'] == 'full-width')
    echo ' class="full-width"'; ?>>
    <!-- Header -->
    <header
        class="navbar navbar-inverse<?php if ($template['header'] == 'fixed-top')
            echo ' navbar-fixed-top'; else if ($template['header'] == 'fixed-bottom')
            echo ' navbar-fixed-bottom'; ?>">
        <div class="navbar-inner">
            <div class="row-fluid">
                <div class="span4 hidden-phone">
                    <ul class="nav pull-left">
                        <li class="visible-desktop">
                            <a href="javascript:void(0)" id="toggle-side-content">
                                <i class="icon-reorder"></i>
                            </a>
                        </li>

                        <li class="visible-tablet">
                            <a href="javascript:void(0)" data-toggle="collapse" data-target=".nav-collapse">
                                <i class="icon-reorder"></i>
                            </a>
                        </li>

                        <li class="divider-vertical remove-margin"></li>
                    </ul>
                </div>

                <div class="span4 text-center">
                    <!-- Logo -->
                    <a href="index.php" class="brand">
                        <img src="<?php echo Yii::app()->BaseUrl . '/images/back/logo.png'; ?>" alt="logo">
                    </a>
                    <!-- END Logo -->

                    <div id="loading" class="hide"><i class="icon-spinner icon-spin"></i></div>
                </div>

                <div id="header-nav-section" class="span4 clearfix">
                    <ul class="nav pull-left visible-phone">
                        <li>
                            <a href="javascript:void(0)" data-toggle="collapse" data-target=".nav-collapse">
                                <i class="icon-reorder"></i>
                            </a>
                        </li>
                        <li class="divider-vertical remove-margin"></li>
                    </ul>
                </div>
            </div>
        </div>
    </header>
    <!-- END Header -->

    <!-- Left Sidebar -->
    <aside id="page-sidebar" class="nav-collapse collapse<?php if ($template['sidebar'] == 'sticky')
        echo ' sticky'; ?>">
        <div class="side-scrollable">
            <!-- Mini Profile -->
            <a target="_top" href="<?php echo TreTodayUrl::backendUrl() ?>"><img
                    src="<?php echo Yii::app()->BaseUrl . '/images/back/logo.png'; ?>"></a>
            <!-- END Mini Profile -->

            <!-- Sidebar Tabs -->
            <div class="sidebar-tabs-con">
                <div class="tab-content">
                    <div class="tab-pane active" id="side-tab-menu">
                        <nav id="primary-nav">
                            <ul>
                                <?php $primaryNav = $this->menuBarItem();
                                foreach ($primaryNav as $key => $link) {
                                    $linkClass = '';

                                    // Get link's vital info
                                    $url = (isset($link['url']) && $link['url']) ? $link['url'] : '#';
                                    $active = (isset($link['url']) && ($template['active_page'] == $link['url'])) ? ' active' : '';
                                    $icon = (isset($link['icon']) && $link['icon']) ? '<i class="' . $link['icon'] . '"></i>' : '';

                                    // Check if we need add the class active to the li element (only if a sublink is active)
                                    $liActive = '';
                                    $meuLink = '';

                                    if (isset($link['sub']) && $link['sub']) {
                                        foreach ($link['sub'] as $subLink) {
                                            if (in_array($template['active_page'], $subLink)) {
                                                $liActive = ' class="active"';
                                                break;
                                            }

                                            // Check and sublinks for active class if they exist
                                            if (isset($subLink['sub']) && $subLink['sub']) {
                                                foreach ($subLink['sub'] as $sub2Link) {
                                                    if (in_array($template['active_page'], $sub2Link)) {
                                                        $liActive = ' class="active"';
                                                        break;
                                                    }
                                                }
                                            }
                                        }

                                        $meuLink = 'menu-link';
                                    }

                                    if ($meuLink || $active)
                                        $linkClass = ' class="' . $meuLink . $active . '"';
                                    ?>
                                    <li<?php echo $liActive; ?>>
                                        <a href="<?php echo $url; ?>"<?php echo $linkClass; ?>><?php echo $icon . $link['name']; ?></a>
                                        <?php if (isset($link['sub']) && $link['sub']) { ?>
                                            <ul>
                                                <?php foreach ($link['sub'] as $subLink) {
                                                    $linkClass = '';

                                                    // Get sublink's vital info
                                                    $url = (isset($subLink['url']) && $subLink['url']) ? $subLink['url'] : '#';
                                                    $active = (isset($subLink['url']) && ($template['active_page'] == $subLink['url'])) ? ' active' : '';

                                                    // Check if we need add the class active to the li element (only if a sublink is active)
                                                    $li2Active = '';
                                                    $subMenuLink = '';

                                                    if (isset($subLink['sub']) && $subLink['sub']) {
                                                        foreach ($subLink['sub'] as $sub2Link) {
                                                            if (in_array($template['active_page'], $sub2Link)) {
                                                                $li2Active = ' class="active"';
                                                                break;
                                                            }
                                                        }

                                                        $subMenuLink = 'submenu-link';
                                                    }

                                                    if ($subMenuLink || $active)
                                                        $linkClass = ' class="' . $subMenuLink . $active . '"';
                                                    ?>
                                                    <li<?php echo $li2Active; ?>>
                                                        <a href="<?php echo $url; ?>"<?php echo $linkClass; ?>><?php echo $subLink['name']; ?></a>
                                                        <?php if (isset($subLink['sub']) && $subLink['sub']) { ?>
                                                            <ul>
                                                                <?php foreach ($subLink['sub'] as $sub2Link) {
                                                                    // Get vital info of sublinks
                                                                    $url = (isset($sub2Link['url']) && $sub2Link['url']) ? $sub2Link['url'] : '#';
                                                                    $active = (isset($sub2Link['url']) && ($template['active_page'] == $sub2Link['url'])) ? ' class="active"' : '';
                                                                    ?>
                                                                    <li>
                                                                        <a href="<?php echo $url; ?>"<?php echo $active ?>><?php echo $sub2Link['name']; ?></a>
                                                                    </li>
                                                                <?php } ?>
                                                            </ul>
                                                        <?php } ?>
                                                    </li>
                                                <?php } ?>
                                            </ul>
                                        <?php } ?>
                                    </li>
                                <?php } ?>
                            </ul>
                        </nav>
                    </div>
                </div>
            </div>
            <!-- END Sidebar Tabs -->
        </div>
    </aside>
    <!-- END Left Sidebar -->

    <div id="pre-page-content">
        <h1><?php echo $this->layoutPageTitle; ?><br>
            <small><?php echo $this->layoutPageDescription; ?></small>
        </h1>
    </div>

    <div id="page-content">
        <ul class="breadcrumb" data-spy="affix" data-offset-top="250">
            <li>
                <a href="<?php echo TreTodayUrl::backendUrl(); ?>"><i class="glyphicon-display"></i></a> <span
                    class="divider"><i
                        class="icon-angle-right"></i></span>
            </li>
            <?php foreach ($this->breadcrumbs as $label => $link): ?>
                <?php if (!$link) { ?>
                    <li class="active">
                        <?php echo $label; ?>
                    </li>
                <?php } else { ?>
                    <li>
                        <a href="<?php echo $link; ?>">
                            <!--                    <a href="#">-->
                            <?php echo $label; ?>
                        </a> <span class="divider"><i class="icon-angle-right"></i></span>
                    </li>
                <?php } ?>
            <?php endforeach; ?>
        </ul>

        <?php echo $content; ?>
    </div>

    <!-- Footer -->
    <footer>
        <div class="pull-right">
            ALL RIGHTS RESERVED
        </div>
        <div class="pull-left">
            © 2014 TreToday™
        </div>
    </footer>
    <!-- END Footer -->
</div>
<!-- END Page Container -->

<!-- Scroll to top link, check main.js - scrollToTop() -->
<a href="#" id="to-top"><i class="icon-chevron-up"></i></a>

<!-- User Modal Account, appears when clicking on 'User Settings' link found on user dropdown menu (header, top right) -->
<div id="modal-user-account" class="modal hide fade">
    <!-- Modal Body -->
    <div class="modal-body remove-padding">
        <!-- Modal Tabs -->
        <div class="block-tabs">
            <div class="block-options">
                <a href="javascript:void(0)" class="btn btn-danger" data-dismiss="modal"><i class="icon-remove"></i></a>
            </div>
            <ul class="nav nav-tabs" data-toggle="tabs">
                <li class="active"><a href="#modal-user-account-account"><i class="icon-cog"></i> Account</a></li>
            </ul>
            <div class="tab-content">
                <!-- Account Tab Content -->
                <div class="tab-pane active" id="modal-user-account-account">
                    <form action="index.php" method="post" class="form-horizontal" onsubmit="return false;">
                        <div class="control-group">
                            <label class="control-label" for="modal-account-username">Username</label>

                            <div class="controls">
                                <input type="text" id="modal-account-username" name="modal-account-username"
                                       value="admin" class="disabled" disabled>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="modal-account-email">Email</label>

                            <div class="controls">
                                <input type="text" id="modal-account-email" name="modal-account-email"
                                       value="admin@exampleapp.com">
                            </div>
                        </div>
                        <h4 class="sub-header">Change Password</h4>

                        <div class="control-group">
                            <label class="control-label" for="modal-account-pass">Current Password</label>

                            <div class="controls">
                                <input type="password" id="modal-account-pass" name="modal-account-pass">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="modal-account-newpass">New Password</label>

                            <div class="controls">
                                <input type="password" id="modal-account-newpass" name="modal-account-newpass">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="modal-account-newrepass">Retype New Password</label>

                            <div class="controls">
                                <input type="password" id="modal-account-newrepass" name="modal-account-newrepass">
                            </div>
                        </div>
                    </form>
                </div>
                <!-- END Account Tab Content -->
            </div>
        </div>
        <!-- END Modal Tabs -->
    </div>
    <!-- END Modal Body -->

    <!-- Modal footer -->
    <div class="modal-footer">
        <button class="btn btn-success" data-dismiss="modal"><i class="icon-save"></i> Save</button>
    </div>
    <!-- END Modal footer -->
</div>
<!-- END User Modal Settings -->

<script type="text/javascript">
    $(document).ready(function () {
        TreToday.baseUrl = '<?php echo Yii::app()->BaseUrl ?>';
    });
</script>
</body>
</html>

